
import java.net.InetAddress;
import java.net.UnknownHostException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;

import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.ClusterStatus;

public class Cs {

    public static void main(String[] args) throws Exception
    {
        Configuration conf = new Configuration();

        try {
            String hostname = InetAddress.getLocalHost().getHostName();
            String trackerPort = "8021";
            conf.set("mapred.job.tracker", hostname + ":" + trackerPort);
            conf.addResource(new Path("$SP_HADOOP_CONF/core-site.xml"));
            conf.addResource(new Path("$SP_HADOOP_CONF/hdfs-site.xml"));
        }
        catch (UnknownHostException unk) {
            System.out.println(" Unexpected error during getHostName(). "
                      + unk.getMessage() );
            throw new RuntimeException(unk);
        }

        JobConf jobConf = new JobConf(conf);
        JobClient client = new JobClient(jobConf);

        ClusterStatus cs = client.getClusterStatus();

        System.out.println("Max map tasks: " + cs.getMaxMapTasks());
        System.out.println("Map tasks:" + cs.getMapTasks());
        System.out.println("Max reduce tasks: " + cs.getMaxReduceTasks());
        System.out.println("Reduce tasks:" + cs.getReduceTasks());
        System.out.println("Task trackers:" + cs.getTaskTrackers());

        System.out.println("Good");
    }
}
